package route

import (
	"github.com/gin-gonic/gin"
	"net/http"
	v1 "thinkgin/app/blog/controller/v1"
	"thinkgin/app/index/controller"
	"thinkgin/extend/middleware"
	"thinkgin/extend/setting"
)

/*核心路由*/
func InitRouter() *gin.Engine {
	r := gin.New()
	r.Use(gin.Logger(), gin.Recovery(), middleware.LoggerToFile())
	gin.SetMode(setting.RunMode)

	apiv1 := r.Group("/api/v1")
	{
		//获取标签列表
		apiv1.GET("/tags", v1.GetTags)
		//新增标签
		apiv1.POST("/tags", v1.AddTag)
		//编辑标签
		apiv1.PUT("/tags/:id", v1.EditTag)
		//删除标签
		apiv1.DELETE("/tags/:id", v1.DelTag)

		//——————————————————————————————————————分割线——————————————————————————————————————————
		//获取指定文章
		apiv1.GET("/articles/:id", v1.GetArticle)
		//获取文章列表
		apiv1.GET("/articles", v1.GetArticles)
		//新增文章
		apiv1.POST("/articles", v1.AddArticle)
		//编辑文章
		apiv1.PUT("/articles/:id", v1.EditArticle)
		//删除文章
		apiv1.DELETE("/articles/:id", v1.DelArticle)

	}

	//——————————————————————————————————————分割线-下面是首页数据数据——————————————————————————————————————————
	index := r.Group("/index/")
	{
		index.GET("/hello", controller.HelloWord) /*测试输出Hello Word*/
		//apiv1.GET("/hello", v1.HelloWord) /*测试输出Hello Word*/
	}

	r.LoadHTMLGlob("app/index/view/*")
	r.GET("/", func(c *gin.Context) {
		c.HTML(http.StatusOK, "index.html", gin.H{"title": "我是测试"})
	})
	return r
}
